﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Mesuro.Graphing.PropertiesControls {
	/// <summary>
	/// Interaction logic for UserControl1.xaml
	/// </summary>
	public partial class ColorEditor : UserControl {

		#region DP: Color
		public static readonly DependencyProperty ColorProperty = DependencyProperty.Register( "Color", typeof( Color ), typeof( ColorEditor ), new PropertyMetadata( Colors.Black ) );
		public Color Color {
			get { return (Color)GetValue( ColorProperty ); }
			set { SetValue( ColorProperty, value ); }
		}
		#endregion

		#region DP: AlphaVariable
		public static readonly DependencyProperty AlphaVariableProperty = DependencyProperty.Register( "AlphaVariable", typeof( bool ), typeof( ColorEditor ), new PropertyMetadata( true, AlphaVariableChangedStatic ) );
		public bool AlphaVariable {
			get { return (bool)GetValue( AlphaVariableProperty ); }
			set { SetValue( AlphaVariableProperty, value ); }
		}
		private static void AlphaVariableChangedStatic( DependencyObject sender, DependencyPropertyChangedEventArgs e ) {
			//((ColorEditor)sender).OnAlphaVariableChanged();
		}
		#endregion

		public ColorEditor() {
			InitializeComponent();
		}

		private void sliderChanged( object sender, RoutedPropertyChangedEventArgs<double> e ) {
			Color = Color.FromArgb( (byte)sldAlpha.Value, (byte)sldRed.Value, (byte)sldGreen.Value, (byte)sldBlue.Value );
		}

	}
	[ValueConversion( typeof( Color ), typeof( Color ) )]
	public class ColorGradientConverter : IValueConverter {

		public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
			Color src = (Color)value;
			byte a = 0xFF, r = src.R, g = src.G, b = src.B;
			switch ((string)parameter) {
				case "a": a = 0x00; break;
				case "A": a = 0xFF; break;
				case "r": r = 0x00; break;
				case "R": r = 0xFF; break;
				case "g": g = 0x00; break;
				case "G": g = 0xFF; break;
				case "b": b = 0x00; break;
				case "B": b = 0xFF; break;
			}
			return Color.FromArgb( a, r, g, b );
		}

		public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
			throw new NotImplementedException();
		}
	}
}
